/**
*  \file    ../cfg/supervisor.h
*
*  \brief   supplementary header file to automatic generated one .../app/supervisor.h for su�ervisor.* module
*
*  \author francois  <yves-jocelyn.francois@linde-mh.de>
*
*
*/

/*================================================[ public includes  ]================================================*/
#ifndef SUPERVISOR_CFG_H
#define SUPERVISOR_CFG_H

#include "../cfg/prj.h"

#include "../input/input.h"
// #include "../specs.h"
// #include "../tract.h"
#include "../specs/specs.h"
#include "../specs/specs_hw.h"
// #include "../motor.h"
// #include "../steer.h"
#include "../output/output.h"
// #include "../battery.h"
// #include "../operator.h"
#include "../app/app.h"
#include "../dtc/dtc.h"
#include "../parameter/service.h"
#include "../cancom/can_int_rx.h"

#include "../lithium_ion/li_ion.h"
#include "../lithium_ion/li_ion_pred_bat.h"
#include "../lithium_ion/li_ion_term.h"

// #include "../can_func.h"
#include "../supervisor/supervisor.h"

#if 0
#ifdef SC_UC2GEN
#define ErrCheck(dtc, act) PeerSendDTCDelayed(dtc)
#else
#define ErrCheck(dtc, act) sdummy_func()
#endif
#endif

#include <math.h>
#include <stdlib.h>

/*================================================[ public variables ]================================================*/

/*================================================[ public functions ]================================================*/

struct 
{
   int ena;
   int sts;
}ou_Rel,ou_Con;

struct triboot_legacy_2
{
   U32 sw_reset_reason;    /**< reason for a software reset */
   U32 wdt_reset_reason;   /**< reason for a watchdog reset */
   U32 reset_reason;
};
#if 0
/*================================================[ public datatypes ]================================================*/
/* I/O for lithium-ion-battery module                                                                                 */
typedef struct
{
   /* ======= */
   /* System: */
   /* ======= */
   S16 s16State;                                  /* SYMTAB name='li_ion::sLiIon.s16State',
                                                            unit='-',
                                                            label='li-ion state-machine' ,
                                                            type='S16L', min=-100, max=100, slope=1 */
   S16 s16Counter;                                /* State-Counter */
   S16 s16Error;                                  /* SYMTAB name='li_ion::sLiIon.s16Error',
                                                            unit='-',
                                                            label='li-ion startup errors' ,
                                                            type='S16L', min=-100, max=100, slope=1 */
   S16 s16SDORetry;                               /* Retries-Variable */

   /* ======= */
   /* Inputs: */
   /* ======= */

   /* Analog: */
   F32 f32BatteryVolt_K41;                        /* SYMTAB name='li_ion::sLiIon.f32BatteryVolt_K41'  ,
                                                            unit='V'    ,
                                                            label='(:41K) Battery voltage' ,
                                                            type='F32L'  ,  min=-1      , max=120     , slope=1 */
   F32 f32CodeLiIon;                              /* SYMTAB name='li_ion::sLiIon.f32CodeLiIon'  ,
                                                            unit='V'    ,
                                                            label='(:84K) Codepin lithium-ion-battery fitted' ,
                                                            type='F32L'  ,  min=-1      , max=15      , slope=1 */
   U8  in_bLiIon;

   /* CAN: */
   /* 0x70D: Heartbeat */
   U8  CAN_LiIoBMSB_State;                        /* CAN: Heartbeat-Info from Battery-Managment-System                                   */

   /* 0x18D: PDO1 */
   F32 CAN_LiIoBMS_BatteryCurrent_A;              /* CAN: PDO1 (0x18D) Byte 0-2: Battery-Current[A]                                      */
   F32 CAN_LiIoBMS_BatteryVoltage_V;              /* CAN: PDO1 (0x18D) Byte 3-5: Battery-Voltage[V]                                      */
   U8  CAN_LiIoBMS_BatteryStatus;                 /* CAN: PDO1 (0x18D) Byte 6:   Status of Lithium-Ion Battery                           */
   U8  CAN_LiIoBMS_StateOfHealth;                 /* CAN: PDO1 (0x18D) Byte 7:   State of Health [%]                                     */

   /* 0x28D: PDO2 */
   F32 CAN_LiIoBMS_MaxChargeCurrent_2sec_A;       /* CAN: PDO2 (0x28D) Byte 0-1: LiIo battery max. short-term charge current [A]         */
   F32 CAN_LiIoBMS_MaxDischargeCurrent_2sec_A;    /* CAN: PDO2 (0x28D) Byte 2-3: LiIo battery max. short-term discharge current [A]      */
   F32 CAN_LiIoBMS_MaxChargeCurrent_100sec_A;     /* CAN: PDO2 (0x28D) Byte 4-5: LiIo battery max. short-term charge current [A]         */
   F32 CAN_LiIoBMS_MaxDischargeCurrent_100sec_A;  /* CAN: PDO2 (0x28D) Byte 6-7: LiIo battery max. short-term discharge current [A]      */

   /* 0x48D: PDO4 */
   F32 CAN_LiIoBMS_MinDischargeVoltage_V;         /* CAN: PDO4 (0x48D) Byte 0-2: LiIo battery min. discharge voltage [V]                 */
   F32 CAN_LiIoBMS_MaxChargeVoltage_V;            /* CAN: PDO4 (0x48D) Byte 3-5: LiIo battery max. charging voltage [V]                  */
   U8  CAN_LiIoBMS_SOCwithoutSOH;                 /* CAN: PDO4 (0x48D) Byte 6:   LiIo battery charge (battery health not considered) [%] */
   U8  CAN_LiIoBMS_SOCwithSOH;                    /* CAN: PDO4 (0x48D) Byte 7:   LiIo battery charge (battery health considered) [%]     */

   /* 0x301: PDO5 */
   F32 CAN_LiIoBMS_OutputVoltage_V;               /* CAN: PDO5 (0x301) Byte 0-2: LiIo battery output voltage [V]                         */
   U32 CAN_LiIoBMS_MaxDischargePower_2sec;        /* CAN: PDO5 (0x301) Byte 3-4: LiIo battery max. short-term discharge power [W]        */
   U32 CAN_LiIoBMS_MaxChargePower_2sec;           /* CAN: PDO5 (0x301) Byte 5-6: LiIo battery max. short-term charging power [W]         */

   /* SDO's */
   U32 CAN_BatterySerialNo;                       /* CAN: Battery-Serial-Number 05.09.2014/TW -> U32                                     */
   U32 CAN_BatteryEnergy;                         /* CAN: Battery's energy content in [Wh]                                               */
   U8  CAN_vin[0];                  /* CAN: Truck's vehicle identification number                                          */

   /* ======== */
   /* Outputs: */
   /* ======== */
   S16 s16BatteryType;                            /* Typ der angeschlossenen und authentifizierten Batterie */

   /* =================== */
   /* Remaining Work-Time */
   /* =================== */
   BO  bInitCurrentVoltage;
   F32 f32RWTActualEnergy_Wh;                     /* SYMTAB name='li_ion::sLiIon.f32RWTActualEnergy_Wh'  ,
                                                            unit='Wh'    ,
                                                            label='Actual lithium-ion-battery energy in Wh' ,
                                                            type='F32L'  ,  min=-1      , max=200000      , slope=1 */
   F32 f32BattCurrentAvrg;                        /* SYMTAB name='li_ion::sLiIon.f32BattCurrentAvrg'  ,
                                                            unit='A'    ,
                                                            label='Averaged lithium-ion-battery current' ,
                                                            type='F32L'  ,  min=-1000   , max=1000     , slope=1 */
   F32 f32BattVoltAvrg;                           /* SYMTAB name='li_ion::sLiIon.f32BattVoltAvrg'  ,
                                                            unit='V'    ,
                                                            label='Averaged lithium-ion-battery voltage' ,
                                                            type='F32L'  ,  min=-150   , max=150     , slope=1 */
   F32 f32BattCurrentAvrg_F;                      /* SYMTAB name='li_ion::sLiIon.f32BattCurrentAvrg_F'  ,
                                                            unit='A'    ,
                                                            label='Averaged plus filtered lithium-ion-battery current' ,
                                                            type='F32L'  ,  min=-1000  , max=1000    , slope=1 */
   F32 f32BattVoltAvrg_F;                         /* SYMTAB name='li_ion::sLiIon.f32BattVoltAvrg_F'  ,
                                                            unit='V'    ,
                                                            label='Averaged plus filtered lithium-ion-battery voltage' ,
                                                            type='F32L'  ,  min=-150   , max=150     , slope=1 */
   F32 f32RemWorkTime;                            /* SYMTAB name='li_ion::sLiIon.f32RemWorkTime'  ,
                                                            unit='s'    ,
                                                            label='Lithium-ion-battery remaining work-time' ,
                                                            type='F32L'  ,  min=0  , max=40000    , slope=1 */
   F32 f32RemWorkTimeFilt;                        /* SYMTAB name='li_ion::sLiIon.f32RemWorkTime'  ,
                                                            unit='s'    ,
                                                            label='Lithium-ion-battery filtered remaining work-time' ,
                                                            type='F32L'  ,  min=0  , max=40000    , slope=1 */

   /* ======================= */
   /* Shocklevel 2 Managment: */
   /* ======================= */
   U16 u16DTC_Can[4];

   /* =========== */
   /* Abregelung: */
   /* =========== */
   F32 CAN_LiIoBMS_MaxDischargeCurrent_2sec_F;    /* [A] filtered CAN-signal to avoid strong current drops */

} LITHIUM_ION_IO ;
LITHIUM_ION_IO sLiIon;
#endif
/*================================================[ public defines   ]================================================*/

#define ReadBitArray(bitNo, buffer) (((buffer[bitNo / 16]) >> bitNo % 16) & 1)

#define EUROPE (te_Country == 0)
#define USA (te_Country == 1)

#define LTI_VOID (te_AssistRange == 0)
#define LTI_SELECT (te_AssistRange == 1)
#define LTI_ACTIVE (te_AssistRange == 2)

#define DEBUG_ON 1
#define DEBUG_OFF 0
#define DEBUG_SPV DEBUG_OFF

/* supervisor interface */
#define ErrCheckInit()


#define fabsf fdummy_func
#define delta(x,y) fdummy_func()
/* ===========================================================
 * General Purpose Flags
 * ===========================================================
*/
#define op_bPed input_data.accelerator
#define op_sLev input_data.direction
#define tr_vSen input_data.motor_speed

/* ===========================================================
 * Power Reduction
 * ===========================================================
*/
#define tr_rpReq fdummy_para
#define li_bPowerReduction_iBat FALSE 
#define bPowerReductionUcap FALSE
#define li_PowerReductionPerc fdummy_para
#define mL_vSen    fdummy_para
#define mL_fSet    fdummy_para
#define mR_vSen    fdummy_para
#define mR_fSet    fdummy_para

/* ===========================================================
 * Supply Voltage Signals
 * ===========================================================
*/
#define in_u5VD input_data.adc_voltage[mcu_adc_5VExtSns]
#define in_u13V input_data.adc_voltage[mcu_adc_13_7VSupply]
#define in_uBatT input_data.adc_voltage[mcu_adc_KeySwitch]

#define te_BattType_par 48.0

#define Time in_Time()
#define IsLithiumIonBattery sdummy_func

/* ===========================================================
 * bootup
 * ===========================================================
*/
/* ===========================================================
 * Seat / Belt Switch Logic
 * ===========================================================
*/
#define in_bSeat input_data.seat_switch_1
#define in_bSeat_N input_data.seat_switch_2

/* ===========================================================
 * Direction Lever Signals
 * ===========================================================
*/
/* ===========================================================
 * Speed Reduction / Namur Switch / CAN Request
 * ===========================================================
*/
#define te_bRedu1 sdummy_para
#define te_bRedu2 sdummy_para
#define in_rRedu1 fdummy_para
#define in_rRedu2 fdummy_para

#define MM_CntMonState(x) fdummy_func()
#define MM_CounterReceived(x) fdummy_func()

#define te_DLogAvail sdummy_para
#define tr_vReq_DLogger fdummy_para
#define tr_vReq_COption fdummy_para
#define te_BeltRel sdummy_para
#define in_rBeltRel fdummy_para


/* ===========================================================
 * Gas Pedal Potentiometer
 * ===========================================================
*/
#define in_rPed input_data.accelerator
#define in_rPed_N fdummy_para
#define in_rPed_buf fdummy_para
#define op_rPedRect_buf ldummy_para
#define op_rPedRect ldummy_para

/* ===========================================================
 * Steering Angle Sensor
 * ===========================================================
*/
#define st_rSen fdummy_para /* 20200520 no Steering Angle Sensor*/

/* ===========================================================
 * Traction Speed Sensors (Encoder)
 * ===========================================================
*/
#define in_bHBrake_N input_data.park_break_switch
#define in_bFBrake_N fdummy_para
#define op_bOpe ldummy_para
#define mL_fqSen_buf  fdummy_para
#define mL_fqSen   fdummy_para

/* ===========================================================
 * Traction Safety Relay
 * ===========================================================
*/
#define ou_Rel_ena sdummy_para
#define in_uRelT fdummy_para

/* ===========================================================
 * Line Contactor
 * ===========================================================
*/
#define ou_Con_ena sdummy_para
#define in_uConDrn_filt2 fdummy_para
#define in_uCap_K19 fdummy_para
#define in_uCap_A14 fdummy_para


/* ===========================================================
 * DC-link
 * ===========================================================
*/
#define DISTMEM_APP_READY FALSE
#define ou_DCLinkState sdummy_para
#define ou_DCLinkError sdummy_para

/* ===========================================================
 * Temperature
 * ===========================================================
*/
#define TMotModel sdummy_para
#define TMot sdummy_para
#define mD_TMot fdummy_para
#define spv_VctrlAlive fdummy_para
#define fIPC sdummy_para

/* ===========================================================
 * Brake
 * ===========================================================
*/
#define te_ParkMinder sdummy_para
#define te_ForceLBC sdummy_para

/* ===========================================================
 * Assistance System /  Load Pressure
 * ===========================================================
*/
#define in_rPressLoad fdummy_para

#define in_PressLoad fdummy_para
#define in_PressLoad_buf fdummy_para

/* ===========================================================
 * Assistance System /  Load Height
 * ===========================================================
*/
#define op_bLift input_data.lift_potentiometer_ratio
#define lhs_teach_in_ok fdummy_para
#define lhs_lift_height_valid sdummy_para
#define lhs_lift_height fdummy_para

#define mast_zM_top fdummy_para
#define te_AssistRange fdummy_para
/* ===========================================================
 * Assistance System /  rear axle force (counterforce) / load position evaluation
 * ===========================================================
*/

#define cforce_fSen1 fdummy_para
#define cforce_fSen2 fdummy_para
#define cforce_rSen1 fdummy_para
#define cforce_rSen2 fdummy_para
#define load_xML    fdummy_para

#define truck_cforce_error FALSE 


/* ===========================================================
 * Assistance System /  mast tilt angle
 * ===========================================================
*/

#define MM_CntMonState(x) fdummy_func()
#define MAST_TILTSEN_TRACK_GAIN 0
#define op_bTift ((input_data.tilt_switch > 0)?1:0)
#define in_rTilt fdummy_para

/* ===========================================================
 * Truck Identification / Variant
 * ===========================================================
*/
int Variant;
#define sp_Variant sdummy_para
//#define INVALID 1
#define te_ReleaseMask sdummy_para
#define PassiveMode 0
#define vin_is_valid sdummy_func

/* ===========================================================
 * ECU / Processor RAM ROM EEPROM
 * ===========================================================
 */

#define reset_reason_watchdog 0
#define te_EcuOk sdummy_para

#define te_CalOk sdummy_para

#define te_RatPed_TeachN sdummy_para

//struct triboot_legacy_2 *triboot_dead_drop = &triboot_tmp;
//struct triboot_legacy_2 *triboot_dead_drop_2 = &triboot_tmp;

#define op_bTeachOK ldummy_para
#define te_RatSen_TeachL sdummy_para
#define te_RatSen_TeachR sdummy_para
#define st_bTeachOK sdummy_para
#define te_SpeedLimitCO sdummy_para
#define te_AccelLimitCO sdummy_para
#define te_AccelCrossCO sdummy_para
#define te_Country sdummy_para
#define te_DecelMaxCO sdummy_para
#define te_Decel05kmhCO sdummy_para
#define te_Decel15kmhCO sdummy_para
#define BrandID sdummy_para
#define fOSErr_FactParInvalid sdummy_para

#define te_ADuBatBDI_err sdummy_para
#define te_ADu1M1_L1_err sdummy_para
#define te_ADu1M1_L2_err sdummy_para
#define te_ADu1M1_L3_err sdummy_para
#define te_ADu1M2_L1_err sdummy_para
#define te_ADu1M2_L2_err sdummy_para
#define te_ADu1M2_L3_err sdummy_para
#define fOSErr_ProdParInvalid sdummy_para


/* ===========================================================
 * IPC Monitoring
 * ===========================================================
 */
#define EQU_IPCV_APP_all_tasks sdummy_para

#define distmem_get_app_valid_state sdummy_func
#define distmem_get_state sdummy_func

/* ===========================================================
 * Battery Management
 * ===========================================================
 */
#define MM_CntMonState(x) fdummy_func()
#define MM_CounterReceived(x) fdummy_func()
#define MM_CntMonState(x) fdummy_func()
#define IsLiIonBootUpFinished sdummy_func
#define ba_qBat input_data.bms_soc_without_soh
#define in_bLid fdummy_para
#define in_uBatBDI fdummy_para


/* ===========================================================
 * Analog Current Sensor
 * ===========================================================
 */
#define in_rCurrSen input_data.adc_voltage[mcu_adc_CurrentCutOffIso]


/* ===========================================================
 * Safety Processor / Enable Signals / Output Status Signals
 * ===========================================================
 */
#define in_StRelT fdummy_para
#define in_bStRelT fdummy_para
#define in_EnConDrn fdummy_para
#define in_StMod1M2 fdummy_para
#define in_StMod1M1 sdummy_para
#define mL_CmdPwmEna  fdummy_para
#define ou_Mod_ena sdummy_para
#define mR_CmdPwmEna  fdummy_para

/* ===========================================================
 * Traction Safety Program / Host Monitoring
 * ===========================================================
 */

#define in_uStRelT fdummy_para
#define mS_fSet fdummy_para
#define mS_fSet_c2hi fdummy_para
#define mS_fSet_c2lo fdummy_para
#define mR_fSet_c2hi  fdummy_para
#define mR_fSet_c2lo  fdummy_para

#define mL_fSet_c2hi  fdummy_para
#define mL_fSet_c2lo  fdummy_para
#define mL_fSet_Spv_buf  fdummy_para
#define mR_fSet_Spv_buf  fdummy_para

/* ===========================================================
 * Received Commandos from Lift Processor or Power Module
 * ===========================================================
 */

#define bXSlowD sdummy_para
#define bXCreepD sdummy_para
#define bXStopD sdummy_para
#define mE_StsError_Can sdummy_para
#define mE_HBeatCnt_Can_dev sdummy_para

/* ===========================================================
 * Armrest (X:41/X:37)
 * ===========================================================
 */
#define in_bArmrestClosed fdummy_para
#define in_bArmrestOpened fdummy_para

/* ===========================================================
 * Intervention Declaration
 * ===========================================================
 */


/* ===========================================================
 * list of monitoring data to be recorded with DTC ??? 
 * ===========================================================
 */


#define mL_EncC    fdummy_para
#define mL_EncTc   fdummy_para
#define mL_EncTn   fdummy_para
#define mL_nSen    fdummy_para
#define mL_TMot_Can   fdummy_para
#define mL_TMot    fdummy_para
#define mL_TMos    fdummy_para
#define mR_nSen    fdummy_para
#define mR_TMos    fdummy_para
#define te_ADuBatBDI_par sdummy_para
#define te_ADu1M1_L1_par sdummy_para
#define te_ADu1M1_L2_par sdummy_para
#define te_ADu1M1_L3_par sdummy_para
#define te_ADu1M2_L1_par sdummy_para
#define te_ADu1M2_L2_par sdummy_para
#define te_ADu1M2_L3_par sdummy_para

#define ou_Brk_ena sdummy_para


#define in_uConDrn_theo2 fdummy_para

#define in_uPed fdummy_para
#define in_uPed_N fdummy_para
#define in_b1Ped fdummy_para
#define in_bForw fdummy_para
#define in_bNeut fdummy_para
#define in_bBack fdummy_para
#define in_uConDrn fdummy_para


#define st_rSen1 fdummy_para
#define st_rSen2 fdummy_para


// #define ErrCheckInit fdummy_func
#define ipcv_get_timout_error_max fdummy_func
#define ipcv_get_checksum_error_counter fdummy_func
/*================================================[ public datatypes ]================================================*/


/*====================================================================================================================*/

// extern MM_DATA CAN_MMD_LTID;
// extern MM_DATA CAN_MMD_DLOG;
#endif
/***********************************************************************************************************************
*                             Copyright 2009 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
